package intro.databases.gtCarRental.ui;

import java.sql.ResultSet;
import java.sql.SQLException;

import intro.databases.gtCarRental.GTCRActivity;
import intro.databases.gtCarRental.R;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class RentalHistory extends GTCRActivity {
	LinearLayout table;
	LinearLayout table2;

	@Override
	public void onCreate(Bundle b) {
		super.onCreate(b);
		setContentView(R.layout.rental_information);

		table = (LinearLayout) findViewById(R.id.linearLayout_rentalInformation_table);
		table2 = (LinearLayout) findViewById(R.id.linearLayout_rentalInformation_table2);

		ResultSet rS = dbConn.currentReservations(application.currentUser.username);
		try {
			while(rS.next()) {
				View v = getLayoutInflater().inflate(R.layout.rental_information_tablerow, null);

				TextView date = (TextView) v.findViewById(R.id.textView_rentalInformation_date);
				TextView resTime = (TextView) v.findViewById(R.id.textView_rentalInformation_resTime);
				TextView car = (TextView) v.findViewById(R.id.textView_rentalInformation_car);
				TextView location = (TextView) v.findViewById(R.id.textView_rentalInformation_location);
				TextView amount = (TextView) v.findViewById(R.id.textView_rentalInformation_amount);

				date.setText(rS.getString(1));
				resTime.setText(rS.getString(2));
				car.setText(rS.getString(3));
				location.setText(rS.getString(4));
				amount.setText(rS.getString(5));
				
				table.addView(v);
			}
		} 
		catch (SQLException e) { e.printStackTrace(); }

		rS = dbConn.previousReservations(application.currentUser.username);
		try {
			while(rS.next()) {
				View v = getLayoutInflater().inflate(R.layout.rental_information_tablerow, null);

				TextView date = (TextView) v.findViewById(R.id.textView_rentalInformation_date);
				TextView resTime = (TextView) v.findViewById(R.id.textView_rentalInformation_resTime);
				TextView car = (TextView) v.findViewById(R.id.textView_rentalInformation_car);
				TextView location = (TextView) v.findViewById(R.id.textView_rentalInformation_location);
				TextView amount = (TextView) v.findViewById(R.id.textView_rentalInformation_amount);

				date.setText(rS.getString(1));
				resTime.setText(rS.getString(2));
				car.setText(rS.getString(3));
				location.setText(rS.getString(4));
				amount.setText(rS.getString(5));
				
				table2.addView(v);
			}
		} 
		catch (SQLException e) { e.printStackTrace(); }
	}

}
